Saransh Kacharia
October 29th, 2020
%matplotlib inline
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import scipy
import pandas as pd
from scipy import stats
t = np.linspace(0,np.pi*100,np.int(1e5))
N = 10+np.sin(t)
bkgd = stats.norm.rvs(size=np.int(1e5))*np.sqrt(N)+N
plt.hist(bkgd, 300, density=True)
plt.title('Background Distribution')
plt.xlabel('Background')
plt.ylabel('Density')
plt.show()
1.a.
plt.scatter(t[:1000], bkgd[:1000])
plt.title('Background from 0 to 1000 data points')
plt.xlabel('Time')
plt.ylabel('Background')
plt.show()
1.b.
def plotPoints(start, count, time, background):
plt.scatter(time[start:start+count], background[start:start+count])
plt.title(f'Background from {start} to {start+count} data points')
plt.xlabel('Time')
plt.ylabel('Background')
plt.show()
plotPoints(2000, 2000, t, bkgd)
1.b.
plt.scatter(t[::1000], bkgd[::1000])
plt.title('Background every 1000 data points')
plt.xlabel('Time')
plt.ylabel('Background')
plt.show()
plt.scatter(t, bkgd)
plt.title('All data points')
plt.xlabel('Time')
plt.ylabel('Background')
plt.show()
We can see from this plot that plotting all the data points is not useful. It's just a big blob.
2.a.
plt.hist2d(t, bkgd, bins = 40)
plt.title('Density of Background Values')
plt.xlabel('Time')
plt.ylabel('Background')
cbar = plt.colorbar()
cbar.set_label('Number of Data Points')
plt.show()
2.b. This plot shows the distribution of the background data across time. As we can see, at any given time, the background is most dense around 10 and least dense far away from 10. The color represents this density, with yellow being the most dense and violet being the least dense.
3.a.
time = t%(2*np.pi)
plt.scatter(time, bkgd)
plt.title('Background every 1000 data points')
plt.xlabel('Time')
plt.ylabel('Background')
plt.show()
This plot is still not that usefull because it still looks like a big blob, you can see some 'wavy' shape too it but it is not obvious.
3.b.
plt.hist2d(time, bkgd, bins = 40)
plt.title('Density of Background Values')
plt.xlabel('Time')
plt.ylabel('Background')
cbar = plt.colorbar()
cbar.set_label('Number of Data Points')
plt.show()
In this plot we clearly see a sinusoidal shape to the distribution as time goes from $0$ to $2\pi$. This tells us that the distribution is centered around 10 with slight shifts up and down depending on the time.